<template>
  <div id="itemMain" ref="itemRef"></div>
</template>
<script>
import * as echarts from "echarts";
export default {
  data() {
    return {
      myChart: null,
      option: {},
      colorList: [
        "red",
        "red",
        "red",
        "red",
        "red",
        "red",
        "red",
        "#416AEE",
        "#416AEE",
        "#3B60ED",
        "#75F867",
      ],
    };
  },
  props: {
    obj: {},
  },
  mounted() {
    let chartDom = this.$refs.itemRef;
    this.myChart = echarts.init(chartDom, null, {
      devicePixelRatio: 2.5,
    });
    this.option = {
      backgroundColor: "#121C43",
      title: {
        // text: '外籍人员\n\n' + bfb,
        text: `${this.obj.name} \n  ${this.obj.bfb}%`,
        textStyle: {
          color: "#fff",
          fontSize: 12,
        },
        left: "center",
        bottom: "5%",
        itemGap: 80,
      },
      angleAxis: {
        clockwise: false,
        startAngle: -45,
        axisLine: {
          show: false,
        },
        axisTick: {
          show: false,
        },
        axisLabel: {
          show: false,
        },
        splitLine: {
          show: false,
        },
      },
      radiusAxis: {
        type: "category",
        axisLine: {
          show: false,
        },
        axisTick: {
          show: false,
        },
        axisLabel: {
          show: false,
        },
        splitLine: {
          show: false,
        },
      },
      polar: {
        radius: "100%", //图形大小
      },
      series: [
        {
          type: "gauge",
          roundCap: true,
          radius: "125%",
          center: ["50%", "85%"],
          splitNumber: 0,
          startAngle: 180,
          endAngle: 0,
          z: 4,
          zlevel: 0,
          axisLine: {
            show: true,
            roundCap: true,
            lineStyle: {
              // 轴线样式
              width: 2, // 宽度
              color: [
                [
                  1,
                  new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                    {
                      offset: 0,
                      color: "#0E1B46",
                    },
                    {
                      offset: 0.5,
                      color: "#3D5FD6",
                    },
                    {
                      offset: 1,
                      color: "#0E1B46",
                    },
                  ]),
                ],
              ],
            },
          },
          //分隔线样式
          splitLine: {
            show: false,
          },
          axisLabel: {
            show: false,
          },
          axisTick: {
            show: false,
          },
        },
        //中间
        {
          type: "gauge",
          radius: "155%",
          center: ["50%", "85%"],
          splitNumber: 40,
          startAngle: 180,
          endAngle: 0,
          hoverAnimation: true,
          axisTick: {
            show: false,
          },
          splitLine: {
            show: true,
            length: 5,
            lineStyle: {
              width: 2,
              fontWeight: 400,
              color: "#1A2D78",
            },
          },

          axisLabel: {
            show: false,
          },
          pointer: {
            show: false,
          },
          axisLine: {
            show: false,
          },
          detail: {
            show: false,
          },
        },
        {
          zlevel: 2,
          type: "pie",
          hoverAnimation: false, //鼠标经过的特效
          radius: ["90%", "100%"],
          center: ["50%", "85%"],
          startAngle: 180,
          labelLine: {
            normal: {
              show: false,
            },
          },
          label: {
            normal: {
              position: "center",
            },
          },
          data: [
            {
              value: 100,
              itemStyle: {
                normal: {
                  color: "#AAB9D3",
                },
              },
            },
            {
              value: 100,
              itemStyle: {
                normal: {
                  label: {
                    show: false,
                  },
                  labelLine: {
                    show: false,
                  },
                  color: "rgba(0,0,0,0)",
                  borderWidth: 0,
                },
                emphasis: {
                  color: "rgba(0,0,0,0)",
                  borderWidth: 0,
                },
              },
            },
          ],
        },
        {
          zlevel: 3,
          type: "gauge",
          startAngle: 180,
          endAngle: 0,
          radius: "100%",
          center: ["50%", "85%"],
          progress: {
            show: true,
            width: 5,
          },
          pointer: {
            show: false,
          },
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
          splitLine: {
            show: false,
          },
          axisLabel: {
            show: false,
          },
          detail: {
            show: false,
          },
          data: [
            {
              value: this.obj.bfb,
              itemStyle: {
                normal: { color: this.handleColor(this.obj.bfb) },
              },
            },
          ],
        },
      ],
    };
    this.myChart.setOption(this.option);
  },
  methods: {
    handleColor(index) {
      if (index * 1 == 100) {
        return "#75F867";
      } else if (index * 1 > 95) {
        return "#3B60ED";
      } else if (index * 1 > 90) {
        return "#5470C6";
      } else if (index * 1 > 85) {
        return "#F3C358";
      } else if (index * 1 > 80) {
        return "#FF7070";
      } else {
        return "red";
      }
    },
  },
};
</script>

<style lang="less" scoped>
#itemMain {
  width: 100%;
  height: 100%;
}
</style>
